<?php

namespace app\index\controller\consulting;

use app\index\model\UM as UM;
use app\index\service\MessageService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * ServerMessage 控制器
 * Class ServerMessage
 * @package app\consulting\controller
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 */
class ServerMessage
{
    // 请求参数
    private Request $request;

    private MessageService $service;

    public function __construct(Request $request, MessageService $messageService)
    {
        $this->request = $request;
        $this->service = $messageService;
    }

    /**
     * 发 服务卡片 消息
     * \app\index\model\UM $user
     * @return ApiResponse
     * @url /consulting/server_message/save
     */
    public function save(UM $user): ApiResponse
    {
        $request = $this->request;

        $this->service->addServerMessage($user, $request->param());

        return ApiResponse::success(null);
    }

}
